/**
 * Copyright (c) 2015 www.smarthome.com All rights reserved. <br />
 * 本软件源代码版权归xxxx公司,未经许可不得任意复制与传播.<br />
 *
 */
package com.smarthome.core.workingmonitor.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import com.smarthome.base.service.ShAccountLogService;
import com.smarthome.core.dictionary.AccountLogTypeService;
import com.smarthome.core.workingmonitor.AccountLogService;
import com.smarthome.domain.bean.ShAccountLog;
import com.smarthome.domain.bean.ShAccountLogType;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

@Service("accountLogService")
public class AccountLogServiceImpl implements AccountLogService {

    protected static Logger LOGGER;

    @Resource
    private ShAccountLogService shAccountLogService;

    @Resource
    private AccountLogTypeService accountLogTypeService;

    @Override
    public DataGrid dataGrid(ShAccountLog accountLog, PageHelper page) {
        return shAccountLogService.queryShAccountLogs(accountLog, page);
    }

    @Override
    public List<Combobox> typeCombobox(boolean flag) {
        List<Combobox> result = new ArrayList<>();
        if (flag) {
            Combobox combobox = new Combobox();
            combobox.setValue("");
            combobox.setText("--请选择--");
            combobox.setSelected(true);
            result.add(combobox);
        }
        ShAccountLogType queryLogType = new ShAccountLogType();
        queryLogType.setOrderField("id");
        queryLogType.setOrderFieldType("ASC");
        queryLogType.setIsDel(0L);
        List<ShAccountLogType> accountLogTypes = accountLogTypeService.queryAccountLogTypeList(queryLogType);
        // 转combobox
        for (ShAccountLogType accountLogType : accountLogTypes) {
            Combobox combobox = new Combobox();
            combobox.setValue(accountLogType.getId().toString());
            combobox.setText(accountLogType.getName());
            result.add(combobox);
        }
        return result;
    }

    @Override
    public void saveLog(ShAccountLog accountLog) {
        shAccountLogService.saveOrUpdate(accountLog);
    }

}
